package cn.wolfcode.trip.base.domain;

import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
@ToString
@JsonIgnoreProperties("handler")
public class StrategyDetail extends BaseDomain {
    public static final Integer STATE_DRAFT = 0;
    public static final Integer STATE_RELEASE = 2;

    private String title;
    @JsonFormat(pattern = "yyyy-MM-dd HH-mm-ss",timezone = "GMT+8")
    private Date createTime;
    @DateTimeFormat(pattern = "yyyy-MM-dd HH-mm-ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH-mm-ss",timezone = "GMT+8")
    private Date releaseTime;

    private Integer sequence;

    private StrategyCatalog catalog;

    private String coverUrl;

    private Integer state;

    private StrategyContent strategyContent;

    public String getStateName(){
        String temp = "发布";
        if(state == StrategyDetail.STATE_DRAFT) {
            temp = "草稿";
        }
        return temp;
    }

    public String getJson(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",getId());
        map.put("title",title);
        map.put("coverUrl",coverUrl);
        if(catalog != null){
            map.put("catalogId",catalog.getId());
            map.put("strategyId",catalog.getStrategy().getId());
        }
        map.put("sequence",sequence);
        map.put("state",state);
        return JSONUtils.toJSONString(map);
    }

}